package com.yuan.yblog.search.asyn;

import com.yuan.yblog.common.utils.SpringUtils;
import com.yuan.yblog.search.listener.CanalListener;
import com.yuan.yblog.search.service.EsPostService;

import java.util.TimerTask;

/**
 * 异步task工厂
 */
public class AsyncFactory {

    /**
     *  将mysql的post全量导入ES
     */
    public static TimerTask esImportPost()
    {
        return new TimerTask()
        {
            @Override
            public void run() {
                EsPostService esPostService = SpringUtils.getBean(EsPostService.class);
                esPostService.initImport();
            }
        };
    }

    /**
     *  启动canal监听
     */
    public static TimerTask canalListen()
    {
        return new TimerTask()
        {
            @Override
            public void run() {
                try {
                    SpringUtils.getBean(CanalListener.class).canalListen();
                } catch (Exception e) {
                    throw new RuntimeException("canal监听线程终止：" + e.getMessage());
                }
            }
        };
    }



}
